package com.hnhegui.backend.system.controller;

import com.hnhegui.backend.entity.Result;
import com.hnhegui.backend.system.api.AuthRestApi;
import com.hnhegui.backend.system.dto.request.LoginRequestDTO;
import com.hnhegui.backend.system.dto.response.LoginResponseDTO;
import com.hnhegui.backend.system.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证Controller
 */
@Validated
@RestController
@RequestMapping("/api/auth")
public class AuthController implements AuthRestApi {

    @Autowired
    private AuthService authService;

    /**
     * 用户登录
     */
    public Result<LoginResponseDTO> login(@Validated @RequestBody LoginRequestDTO request) {
        LoginResponseDTO response = authService.login(request);
        return Result.success(response);
    }
    /**
     * 用户登出
     */
    public Result<Void> logout(Long userId) {
        authService.logout(userId);
        return Result.success();
    }

}
